package com.contact.util.util.filters;


public abstract class AbstractDataFilter<D, F> implements DataFilter {
    private static final long serialVersionUID = -5242275400783998539L;

    private transient final DataFilterType filterType;
    private transient final String key;

    private DataFilterValue dataFilterValue;

    protected AbstractDataFilter(DataFilterType filterType, String key) {
        this.filterType = filterType;
        this.key = key;
        setDataFilterValue(new DataFilterValue(null, null, false));
    }

    @Override
    public final String getKey() {
        return key;
    }

    @Override
    public final String getType() {
        return filterType.getKey();
    }

    public final void setHidden(boolean hidden) {
        dataFilterValue.setHidden(hidden);
    }

    @Override
    public final boolean getHidden() {
        return dataFilterValue.isHidden();
    }

    //allow override
    public void setDisplayValue(D displayValue) {
        dataFilterValue.setDisplayValue(displayValue);
    }

    @SuppressWarnings("unchecked")
    @Override
    public D getDisplayValue() {

        return (D) dataFilterValue.getDisplayValue();
    }

    public void setFilterValue(F filterValue) {
        dataFilterValue.setFilterValue(filterValue);
    }

    @SuppressWarnings("unchecked")
    @Override
    public F getFilterValue() {
        return (F) dataFilterValue.getFilterValue();
    }

    @Override
    public final DataFilterValue getDataFilterValue() {
        return dataFilterValue;
    }

    @Override
    public final void setDataFilterValue(DataFilterValue dataFilterValue) {
        this.dataFilterValue = dataFilterValue;
    }

    @Override
    public DataFilterType getFilterType() {
        return filterType;
    }
    
    
}
